unit LoginHistory;

interface
uses
  Forms,
  Windows,
  Classes,
  IniFiles,
  SysUtils;

type
  TLogHistory = class(TObject)
  private
    FlogName: string;
    FLogFile: Textfile;
  protected
    function AddDirSuffix(const Dir: string): string;
  public
    constructor Create;
    destructor Destroy; override;
    function LogSaveFile(sn: string): Boolean;
    function LogLoadFile(state: Integer): Boolean;
  end;

implementation

{ TLogHistory }

constructor TLogHistory.Create;
var
  LogFileName: string;
begin
  inherited;
  FlogName := ExtractFilePath(GetModuleName(HInstance));// + 'log\';
  if not DirectoryExists(FlogName) then
    CreateDir(FlogName);
  LogFileName := AddDirSuffix(FlogName) +'program.dll';// FormatDateTime('yyyymmdd', Now)+ 'History.log';
  AssignFile(FLogFile, LogFileName);
  if not FileEXists(LogFileName) then
    Rewrite(FLogFile)
  else
    Append(FLogFile);
end;

destructor TLogHistory.Destroy;
begin
  CloseFile(FLogFile);
  inherited;
end;

function TLogHistory.LogLoadFile(state: Integer): Boolean;
begin

end;

function TLogHistory.LogSaveFile(sn: string): Boolean;
begin
  Writeln(FLogFile, FormatDateTime('yyyy-mm-dd hh:nn:ss', Now) + ' >>> ' + sn );
end;

function TLogHistory.AddDirSuffix(const Dir: string): string;
begin
  Result := Trim(Dir);
  if Result = '' then Exit;
  if not IsPathDelimiter(Result, Length(Result)) then
    Result := Result + {$IFDEF MSWINDOWS} '\';
{$ELSE} '/';
{$ENDIF};
end;





end.
